package com.qyl.deguru.controller.admin;

import java.util.List;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.qyl.deguru.common.PageModel;
import com.qyl.deguru.dto.Order;
import com.qyl.deguru.service.OrderService;
import com.qyl.deguru.service.impl.OrderServiceImpl;


@Controller
@RequestMapping("/admin/order")
public class OrderController {
	OrderService orderService = new OrderServiceImpl();
	
	@RequestMapping("/getOrders")
	public String getOrder(@RequestParam(name="pageIndex",defaultValue="0") Integer pageIndex,Integer pageSize,
				Order order,ModelMap map){
		PageModel pageModel = new PageModel();
		//设置当前页
		pageModel.setPageIndex(pageIndex);
		//设置总记录数
		int count = orderService.getCountByOrder(order);
		pageModel.setRecordCount(count);
		
		if(pageSize == null){
			pageSize = 3;
			pageModel.setPageSize(pageSize);
		}
		
		//获取订单列表
		List<Order> orders = orderService.getOrderListByPage(order,pageModel);
		//返回数据
		map.addAttribute("orders", orders);
		map.addAttribute("order", order);
		map.addAttribute("pageModel", pageModel);
		return "order/orderList";
	}
}
